//
//  UIBarButtonItem+Extension.swift
//  ZHLEEBlog_swift_pro
//
//  Created by ZHLEEBlander on 15/10/11.
//  Copyright © 2015年 ZHLEEBlander. All rights reserved.
//

import Foundation
import UIKit

extension UIBarButtonItem{

    class func item(target: AnyObject?, action: Selector, imageName: String = "", title : String = "") ->UIBarButtonItem {
        let button = UIButton()
        button.addTarget(target, action: action, forControlEvents: UIControlEvents.TouchUpInside)
        
        if imageName.characters.count > 0{

            button.setImage(UIImage(named: imageName), forState: UIControlState.Normal)
            button.setImage(UIImage(named: "\(imageName)_highlighted"), forState: UIControlState.Highlighted)
        }
        
        if title.characters.count > 0{
        
            button.setTitle(title, forState: UIControlState.Normal)
            button.titleLabel?.font = UIFont.systemFontOfSize(14)
            button.setTitleColor(UIColor(red: 80/255, green: 80/255, blue: 80/255, alpha: 1), forState: UIControlState.Normal)
            button.setTitleColor(UIColor.orangeColor(), forState: UIControlState.Highlighted)
        }
        button.sizeToFit()
        
        return UIBarButtonItem(customView: button)
    }
}

